﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Data;

public partial class Contraseña : System.Web.UI.Page
{
    private string To;
    private string Subject;
    private string Body;

    private MailMessage mail;
    private Attachment Data;


    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnEnviar_Click(object sender, EventArgs e)
    {

        DataView tablausuario = (DataView)sdsRecuperar.Select(DataSourceSelectArguments.Empty);
        string contrasenia = tablausuario[0][2].ToString();
        string usuario = txtUsuario.Text;

        if (!(txtCorreo.Text.Trim() == ""))
        {
            To = txtCorreo.Text;
            Subject = "Recuperar contraseña";
            Body = "Hola " + usuario + " Tu contraseña es " + contrasenia;

            mail = new MailMessage();
            mail.To.Add(new MailAddress(this.To));
            mail.From = new MailAddress("stanleynik92@hotmail.com");
            mail.Subject = Subject;
            mail.Body = Body;
            mail.IsBodyHtml = false;

            SmtpClient client = new SmtpClient("smtp.live.com", 587);
            using (client)
            {
                client.Credentials = new System.Net.NetworkCredential("kurt_guille93@hotmail.com","2839yola41");
                client.EnableSsl = true;
                client.Send(mail);
            }
            LblMensaje.Text = "Se ha enviado un mensaje a tu correo";
            txtCorreo.Text = "";
            txtUsuario.Text = "";
        }
    }
}